package com.ecommerce.dal.common;

import java.util.Date;
import java.util.List;

import com.ecommerce.dal.entity.User;
import com.ecommerce.dal.service.impl.UserManagerService;

public class TestUser {
	
	public TestUser(UserManagerService userManagerService){
		/** insert **/
		
    	User user = new User();
//    	user.setUserId(1L);
    	long id = 1;
    	user.setFirstName("belal");
    	//Increment
    	user.setUserName("belal"+id);
    	user.setPassword("123");
    	user.setLastName("galal");
    	user.setNewsletter(true);
    	user.setBirthDate(new Date());
    	user.setGender("male");
    	user.setJoinDate(new Date());
    	userManagerService.saveUser(user);
 
    	/** select **/
//    	User user2 = userManagerService.retrieveUser("belal4");
    	User user2 = userManagerService.retrieveUser("belal1","123");
    	
    	System.out.println(user2.getFirstName() + "Does User Name belal4 exist? "+userManagerService.checkUserIfExists("belal4"));
 
    	/** update **/
    	user2.setFirstName("ahmed");
    	userManagerService.updateUser(user2);
    	
    	List<User> userList = userManagerService.retrieveAllUsers();
    	for (User userX : userList){
    		System.out.println("User Name: " + userX.getUserName() + " First Name: "+ userX.getFirstName() + " Last Name: " + userX.getLastName() );
    	}
    	System.out.println("---------------------------------");
    	userList = userManagerService.retrieveNewsletterUsers();
    	System.out.println("//Excluded belal2 , belal3 , belal 4 from the list");
    	for (User userX : userList){
    		System.out.println("User Name: " + userX.getUserName() );
    	}
 
    	/** delete **/
//    	userManagerService.delete(user2);
 
    	System.out.println("Done");
	}

}